package com.qf.agro.service.warning.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.mapper.warning.EarlyWarningMapper;
import com.qf.agro.pojo.warning.EarlyWarning;
import com.qf.agro.service.warning.EarlyWarningService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EarlyWarningServiceImpl implements EarlyWarningService {
    @Autowired
    private EarlyWarningMapper earlyWarningMapper;
    @Override
    public Page<EarlyWarning> findPage(Integer pageNum, Integer pageSize, String name, Long facilitiesId) {
        //1.创建分页对象
        Page<EarlyWarning> page = new Page<>(pageNum,pageSize);
        //2.创建查询条件对象
        LambdaQueryWrapper<EarlyWarning> queryWrapper = new LambdaQueryWrapper<>();
        //3.条件
        queryWrapper.like(facilitiesId!=null,EarlyWarning::getFacilitiesId,facilitiesId);
        queryWrapper.like(StringUtils.isNotEmpty(name),EarlyWarning::getDeviceName,name);//输入设备名查询
        queryWrapper.eq(facilitiesId!=null,EarlyWarning::getFacilitiesId,facilitiesId);
        //4.查询
        page = earlyWarningMapper.selectPage(page, queryWrapper);
        //5.
        return page;
    }
}
